package main

import (
	fmt "fmt"
	"strconv"
)

func main() {
	//基本数据类型转string
	var num1 int = 99
	var num2 float64 = 23.456
	var b bool = true
	var myChar byte = 'h'
	var str string
	//使用第一种方式转换
	str = fmt.Sprintf("%d", num1)
	fmt.Printf("str type %T str=%q\n", str, str)
	str = fmt.Sprintf("%f", num2)
	fmt.Printf("str type %T str=%q\n", str, str)
	str = fmt.Sprintf("%t", b)
	fmt.Printf("str type %T str=%q\n", str, str)
	str = fmt.Sprintf("%c", myChar)
	fmt.Printf("str type %T str=%q\n", str, str)

	//第二种方式
	var num3 int = 99
	var num4 float64 = 23.456
	//var b2 bool =true
	str = strconv.FormatInt(int64(num3), 10) //base 进制单位
	fmt.Printf("str typoe %T str=%q\n", str, str)
	//strconv.FormatFloat(num4,'f',10,64)
	//说明:'f' 格式10:表示小数位保留10位 64:表示这个小数是float64
	str = strconv.FormatFloat(num4, 'f', 10, 64)
	fmt.Printf("str typoe %T str=%q\n", str, str)
	//strconv包中有一个函数itoa
	var num5 int = 4567
	str = strconv.Itoa(num5)
	fmt.Printf("str typoe %T str=%q\n", str, str)
	//string转基础数据类型

}
